<!DOCTYPE html>
<html lang="en">
<title>门店管理-门禁设备列表</title>
<#import "/layout/layout.html" as body/>
<@body.page>
<style>
    .dataTables_empty {
        display: none
    }
</style>

<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-lg-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title overflow">
                    <h5 class="pull-left">门禁设备列表</h5>
                    <a href="${baseUrl}system/accessDevice/add" class="btn btn-sm btn-primary pull-right"
                       style="margin-left: 10px; ">新增门禁</a>
                </div>
                <div class="ibox-content">
                    <div class="table-responsive">
                        <form class="form-inline" role="form">

                            <div class="form-group">
                                <label for="storeName">门店名称 ：</label>
                                <input class="form-control" type="text" id="storeName" name="storeName" placeholder="输入门店名称" />
                            </div>
                            <div class="form-group margin-left">
                                <label>门店：</label>
                                <select class="form-control" id="storeId" name="storeIdQuery">
                                    <option value="">全部</option>
                                    <#if stores??>
                                        <#list stores as store>
                                            <option value="${store.id}">${store.storeName}</option>
                                        </#list>
                                    </#if>
                                </select>
                            </div>
                            <div class="form-group margin-left">
                                <label>门禁位置：</label>
                                <select class="form-control" id="storeLocation" name="storeLocationQuery">
                                    <option value="">全部</option>
                                    <!--<option value="1">大门</option>-->
                                    <option value="2">操房</option>
                                    <option value="3">自助</option>
                                    <!--<option value="4">浴室</option>-->
                                     
                                </select>
                            </div>
                            <div class="form-group margin-left">
                                <label>密码类型：</label>
                                <select class="form-control" id="pwdType" name="pwdTypeQuery">
                                    <option value="">全部</option>
                                    <option value="1">动态密码</option>
                                    <option value="0">固定密码</option>
                                </select>
                            </div>
                            <div class="form-group margin-left">
                                <label>状态：</label>
                                <select class="form-control" id="deviceStatus" name="deviceStatusQuery">
                                    <option value="">全部</option>
                                    <option value="1">在线</option>
                                    <option value="2">离线</option>
                                    <option value="3">停用</option>
                                </select>
                            </div>
                            <button type="button" class="btn btn-outline btn-primary" style="margin-top: 5px" onClick="accessDevicePage(1)">确认</button>
                        </form>
                        <hr>
                        <table class="table table-hover table-center dataTables-example">
                            <thead>
                            <tr>
                                <th>门店 ID</th>
                                <th>门店名称</th>
                                <th>门店位置</th>
                                <th>操房位置</th>
                                <th>设备密码类型</th>
                                <th>设备序列号</th>
                                <th>设备最后报告时间</th>
                                <th>设备状态</th>
                                <th>操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            <tbody id="list">
                            </tbody>
                            </tbody>
                        </table>
                    </div>
                </div>
                <div class="ibox-footer overflow">
                    <h4 class="pull-left">合计：<span id="count">0</span>个门禁设备</h4>
                    <div id="copot-page" class="pull-right"></div>
                </div>
            </div>
        </div>
    </div>
</div>

<script>

    //教练编辑
    function editCoach(id) {
        window.location = "${baseUrl}system/accessDevice/accessDeviceList?id=" + id;
    }

    $(document).ready(function () {
        //导出excel
//        ExampleFile("教练excel");

        accessDevicePage(1);
    });

    //分页方法
    function accessDevicePage(currentIndex) {
//        debugger
        var param = {
            "pageIndex": currentIndex,
            "pageSize": 10,
            "storeName": $("#storeName").val(),
            "storeId": $("#storeId").val(),
            "storeLocation": $("#storeLocation").val(),
            "pwdType": $("#pwdType").val(),
            "deviceStatus": $("#deviceStatus").val()
        };

        $("#list").empty();
        $.ajax({
            url: "${baseUrl}system/accessDevice/accessDeviceList",
            data: param,
            type: "POST",
            success: function (result) {
                result = JSON.parse(result);
                var html = "";
                //分页
                new Page({
                    parent: $("#copot-page"),
                    nowPage: currentIndex,
                    pageSize: 10,
                    totalCount: result.total,
                    setting: {
                        defaultPage: 5,//默认显示可点击分页的个数
                        firstPageText: "首页",
                        prevPageText: "上一页",
                        nextPageText: "下一页",
                        lastPageText: "尾页"
                    },
                    callback: function (nowPage, totalPage) {
                        accessDevicePage(nowPage);
                    }
                });

                $("#count").text(result.total);


                var storeLocation = null;
                var workoutRoomName = null;
                var deviceSerialId = null;
                var pwdType = null;
                var lastUpdateTime = null;
                var deviceStatus = null;
                $.each(result.records, function (i, data) {
//                    debugger
                    if(data) {
                        if (data.storeLocation) {
                            if (data.storeLocation ==1) {
                                storeLocation = "大门";
                                workoutRoomName = "非操房";
                            } else if (data.storeLocation ==2) {
                                storeLocation = "操房";
                                workoutRoomName = data.workoutRoomName + " ("+data.workoutRoomNum +")";
                            } else if (data.storeLocation ==3) {
                                storeLocation = "自助";
                                workoutRoomName = "非操房";
                            } else if (data.storeLocation ==4) {
                                storeLocation = "浴室";
                                workoutRoomName = "非操房";
                            } else {
                                storeLocation = data.storeLocation;
                                workoutRoomName = "非操房";
                            }
                            if (data.pwdType == 1){
                                deviceSerialId = data.deviceSerialId;
                                lastUpdateTime = data.lastUpdateTime;
                                pwdType = "动态密码";
                            } else if (data.pwdType == 2){
                                deviceSerialId = "无";
                                lastUpdateTime = "无";
                                pwdType = "固定密码" +"("+ data.superPwd +")";
                            }
                            if (lastUpdateTime == 'undefined') lastUpdateTime = "无";
                            if (data.deviceStatus > 0) {
                                if (data.deviceStatus == 1) {
                                    deviceStatus = "在线";
                                } else if (data.deviceStatus == 2) {
                                    deviceStatus = "离线";
                                } else if (data.deviceStatus == 3) {
                                    deviceStatus = "停用";
                                }
                            }
                        }
                    }

                    html += "<tr><td>" + data.storeId + "</td>";
                    html += "<td>" + data.storeName + "</td>";
                    html += "<td>" + storeLocation + "</td>";
                    html += "<td>" + workoutRoomName + "</td>";
                    html += "<td>" + pwdType + "</td>";
                    html += "<td>" + deviceSerialId + "</td>";
                    html += "<td>" + lastUpdateTime + "</td>";
                    html += "<td>" + deviceStatus + "</td>";
                    html += "<td width='100'>";
                    html += "<button type='button' onclick='edit(\"" + data.id + "\")' class='btn btn-default'><i class='fa fa-pencil'></i> 编辑</button>";
//                    if (data.status == 1) {
//                        html += "<button type='button' onclick='offlineCoach(" + data.id + ")' class='btn btn-default'><i class='fa fa-arrow-circle-down'></i> 设备离线</button>";
//                    }
//                  if(data.status == 2){
//                    html += "<button type='button' onclick='deleteCoach("+data.id+")' class='btn btn-default'><i class='fa fa-pencil'></i> 删除</button>";
//                  }
                    html += "</td>";
                    html += "</tr>";
                });
                $("#list").html(html);
            }
        });
    }


    //编辑
    function edit(id) {
        window.location = "add?id="+id;
    }

    //设备离线
    function offlineCoach(id) {

        swal({
            title: "确定要离职吗?",
            text: "离职后不可恢复!",
            type: "question",
            showCancelButton: true,
            confirmButtonColor: "#DD6B55",
            cancelButtonText: "容我三思！",
            confirmButtonText: "离职!",
        }).then(function () {
            $.post("coach_offline", {id: id}, function (result) {
                if (result) {
                    swal("离职成功!", "页面即将重新加载,请稍后...", "success");
                    window.setTimeout(function () {
                        window.location.reload()
                    }, 1000);
                }
            });
        },function () {
        });
    }

</script>

</@body.page>
</html>